package javabase.base.client10.shallow;

import org.junit.Test;

/**
 * @author chengshuai
 * @date 2021/5/2 0:02
 */

public class Client {

    /**
     * 也可以采用构造方法进行copy
     */
    @Test
    public void f2() throws CloneNotSupportedException {
        Father father = new Father("爸爸");
        Student student1 = new Student(20, "张三",father);
        Student student2 = (Student) student1.clone();
        // 注意修改student2的age值 但是没有影响 student1的值
        student2.setAge(22);
        Father father2 = new Father("爸爸2");
//        student2.getFather().setName("爸爸2");
        student2.setFather(father2);
        System.out.println("student1：" + student1);
        System.out.println("student2：" + student2);
    }

    @Test
    public void f1() {
        Father father = new Father("爸爸");
        Student student1 = new Student(20, "张三", father);
        Student student2 = new Student(student1.getAge(), student1.getName(), father);

        System.out.println("student1：" + student1);
        System.out.println("student2：" + student2);
    }
}
